<?php
$a_sAlbums = scandir ('public/uploads/foto-album/albums');
unset ($a_sAlbums [0], $a_sAlbums [1]);
$a_sAlbums = array_values ($a_sAlbums);

$aImages = array ();

foreach ($a_sAlbums as $sAlbum)
{
	$a_sImages = scandir ('public/uploads/foto-album/albums/' . $sAlbum . '/thumbs');
	unset ($a_sImages [0], $a_sImages [1]);
	
	foreach ($a_sImages as $sImage)
	{
		$aImages[] = $sAlbum . '/thumbs/' . $sImage;
	}
}

shuffle ($aImages);
$iRandomImageKey = array_rand ($aImages, 1);

echo '<a href="3/Foto-album/' . str_replace ('/thumbs/', '/', $aImages [$iRandomImageKey]) . '.html"><img src="/uploads/foto-album/albums/' . $aImages [$iRandomImageKey] . '" style="width: 227px;" /></a>';